﻿@model SelfMadeMillionaire.Web.Infrastructure.ViewModels.Account.SubscriptionInfoViewModel


<div class="modal fade" id="result-dialog" tabindex="-1" role="dialog" aria-labelledby="add-dialog-label" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="success-dialog-label"></h4>
			</div>
			<div class="modal-body">
			</div>
			<div class="modal-footer">
				<div class="row">
					<div class="col-sm-12">
						<div class="pull-right">
							<a href="#" class="btn btn-default width80" data-dismiss="modal" id="ModalOk">OK</a>
						</div>
					</div>
				</div>

			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
</div>


<div id="upgrade-block">
	@Html.Partial("Upgrade")
</div>

<div class="form-group" id="paidSection">
	
	<div id="DueBallance" class="balance_block">
		
	</div>


	<div class="newsletter_search_btn">
		<ul style="display: inline; list-style-type: none;">
			<li style="float: left; margin-right: 5px;" class="checkout">
				</li>
			<li style="float: left; margin-right: 5px;">
				<button id="bCancel" class="btn btn-primary green">Cancel</button></li>
			
			<li style="float: right; margin-right: 5px;">
				<a target="_blank" href="@Url.Action("Index", "Terms")" class="btn btn-info money_back_notice_btn">Money back guarantee</a></li>
		</ul>
	</div>
</div>




<script type="text/javascript">

	$(document).ready(function() {
		$("#paidSection").hide();
		$(".hidden-buttons").hide();
	});

	function refreshUpgrade() {
		$("#upgrade-block").load('@Url.Action("SubscriptionInfo", "Profile")');
	}


	$(function() {

		

		$("input[type='radio'][name='@Html.NameFor(m => m.SubscriptionLevel)']").attr("disabled", !$("#@Html.IdFor(m => m.IsSMM)").is(":checked"));

		$("#ModalOk").click(function() {
			refreshUpgrade();
		});


		$(".paid").click(function () {

			$(this).addClass('currentproduct');
			$("button").attr("disabled", true);
			$("#bCancel").attr("disabled", false);


			

			var form = $("#subscription-form");
			if (form.valid()) {
				$.ajax({
					url: "@Url.Action("BuyProduct", "Profile")",
					type: "POST",
					data: { producttype: $(".currentproduct").val() },
					cache: false,
					success: function (result) {
						$("#paidSection").show();
						$("li.checkout").load("@Url.Action("PayPalForm")");
						$("#DueBallance").load("@Url.Action("BalanceDue")");
					}
				});
			}

			return false;


		});

		$("#bCancel").click(function () {

			$.ajax({
				url: "@Url.Action("CancelChanges", "Profile")",
				type: "POST",
				cache: false,
				success: function (result) {
					$("button").attr("disabled", false);
					$("#paidSection").hide();

					$("button").removeClass('currentproduct');
				}
			});

			return false;
		});





		$("#unsubscribeSMM").click(function() {
			var form = $("#subscription-form");
			if (form.valid()) {

			    if (confirm("Please confirm that you want to unsubscribe")) {
					$.ajax({
						url: "@Url.Action("UnsubscribeSMM", "Profile")",
						type: "POST",
						data: form.serialize(),
						cache: false,
						success: function(result) {
							$("#result-dialog .modal-title").text("Message");
							$("#result-dialog .modal-body").html("<p>" + result.message + "</p>");
							$("#result-dialog").modal();
						}
					});
				}
			}

			return false;
		});


		$("#subscribeMMM").click(function() {
			var form = $("#subscription-form");
			if (form.valid()) {

				if (confirm("Subscribe for 'Maggie’s Money Mountain' subscription?")) {
					$.ajax({
						url: "@Url.Action("SubscribeMMM", "Profile")",
						type: "POST",
						data: form.serialize(),
						cache: false,
						success: function(result) {
							$("#result-dialog .modal-title").text("Message");
							$("#result-dialog .modal-body").html("<p>" + result.message + "</p>");
							$("#result-dialog").modal();
						}
					});
				}
			}

			return false;
		});

		$("#unsubscribeMMM").click(function() {
			var form = $("#subscription-form");
			if (form.valid()) {
			    if (confirm("Please confirm that you want to unsubscribe")) {
					$.ajax({
						url: "@Url.Action("UnsubscribeMMM", "Profile")",
						type: "POST",
						data: form.serialize(),
						cache: false,
						success: function(result) {
						    $("#result-dialog .modal-title").text("Message");
							$("#result-dialog .modal-body").html("<p>" + result.message + "</p>");
							$("#result-dialog").modal();
						}
					});
				}
			}

			return false;
		});

		$("#subscribeSMM").click(function () {
			var form = $("#subscription-form");
			if (form.valid()) {
				$.ajax({
					url: "@Url.Action("SubscribeSMMFree", "Profile")",
					type: "POST",
					data: form.serialize(),
					cache: false,
					success: function(result) {
					    $("#result-dialog .modal-title").text("Message");
						$("#result-dialog .modal-body").html("<p>" + result.message + "</p>");
						$("#result-dialog").modal();
					}
				});
			}

			return false;
		});


	});
</script>